package com.techstar.common.jackson;
import java.io.IOException;

import org.apache.commons.lang3.StringUtils;
import org.joda.time.DateTime;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import com.techstar.common.utils.StrToDateTimeUtil;

public class DemoDeserializer extends StdDeserializer<String> {
	private static final long serialVersionUID = 1L;

	protected DemoDeserializer() {
		super(String.class);
	}

	@Override
	public String deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
		if (StringUtils.isBlank(jp.getText())||"null".equals(jp.getText().toLowerCase())) {
			return "空";
		}else {
			DateTime date = StrToDateTimeUtil.strToDateTime(jp.getText());
			return date.getMillis()+"";
		}
	}

	@Override
    public String getNullValue() { 
		return "空"; 
	}
}